import { ADD_TODO, REMOVE_TODO, GET_HOME_BUSINESE } from '../actions/index';

const initialState = {
  todos: [],
  homedata: {
    banner: [],
    moneyList: {},
  },
};

const actionHandlers = {
  [ADD_TODO](state, action) {
    return { ...state, todos: action.todos };
  },
  [REMOVE_TODO](state) {
    return { ...state };
  },
  [GET_HOME_BUSINESE](state, action) {
    return {
      ...state,
      homedata: { banner: action.banner, moneyList: state.homedata.moneyList },
    };
  },
};

const reducer = (state = initialState, action) => {
  const { type, payload } = action;

  const actionHandler = actionHandlers[type];
  if (actionHandler) {
    return actionHandler(state, payload);
  }
  return state;
};

export default reducer;
